package com.example.mqtt.mapper;

import com.example.mqtt.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author qwert
 * @version 1.0.0
 * @create 2025/5/15 21:39
 **/
@Mapper
public interface UserMapper {

    @Insert("""
insert into penguin_user (user_id, username, password, create_time, update_time) 
values (#{userId}, #{username}, #{password}, now(), now())
""")
    void registerUser(User user);

    @Update("""
update penguin_user set is_admin = #{isAdmin} where user_id = #{userId}
""")
    void updateUserAdmin(@Param("isAdmin") boolean isAdmin, @Param("userId") String userId);

    @Select("""
select * from penguin_user where user_id = #{userId}
""")
    User getUserByUserId(String userId);

    @Select("""
select * from penguin_user
""")
    List<User> getUserList();

    @Select("""
select * from penguin_user where username = #{username} and password = #{password};
""")
    User getUserByUserName(@Param("username") String username,
                           @Param("password") String password);

    @Select("""
select * from penguin_user where username = #{username};
""")
    User queryUserByUsername(String username);
}
